<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
    String userid = request.getSession().getAttribute("user_id")==null?"":request.getSession().getAttribute("user_id").toString();
	String rolename = request.getSession().getAttribute("role_name") == null? "": request.getSession().getAttribute("role_name").toString();
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="../../bootstrap-3.3.7/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../bootstrap-3.3.7/dist/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
<link rel="stylesheet" type="text/css" href="../../css/infosearch.css" />
<link rel="stylesheet" type="text/css" href="../../css/background.css" />
<!-- <link rel="stylesheet" href="../../zTree/css/demo.css" type="text/css"> -->
<link rel="stylesheet" href="../../zTree/css/metroStyle/metroStyle.css" type="text/css">
<script type="text/javascript" src="../../bootstrap-3.3.7/dist/js/jquery.min.js"></script>
<script type="text/javascript" src="../../bootstrap-3.3.7/dist/js/bootstrap.js"></script>
<!-- bootstrap表格插件 -->
<script src="../../bootstrap-3.3.7/dist/js/bootstrap-table.js"></script>
<link href="../../bootstrap-3.3.7/dist/css/bootstrap-table.css" rel="stylesheet" />
<script src="../../bootstrap-3.3.7/dist/js/bootstrap-table-zh-CN.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="../../bootstrap-3.3.7/docs/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script type="text/javascript" src="../../js/browser.js"></script>
<script type="text/javascript" src="../../js/search/search.js"></script>
<script type="text/javascript" src="../../zTree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="../../zTree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="../../zTree/js/jquery.ztree.exedit-3.5.js"></script>
</head>
<body>
	<div class="container">
		<input id="role" type="text" hidden="true">
		<input id="userid" type="text" hidden="true">
		<div class="row clearfix">
			<div class="col-md-12 column">
				<%@include file="../common/header.jsp"%>
			</div>
			<div class="col-md-12 column" style="padding-top: 20px">
				<div class="col-md-3 column">
					<select id="category" class="combobox" style="height: 30px; width: 100%; float: left">
						<c:choose>
							<c:when test="${category=='name'}">
								<option value="name" selected="selected">篇名</option>
							</c:when>
							<c:otherwise>
								<option value="name">篇名</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='author'}">
								<option value="author" selected="selected">作者</option>
							</c:when>
							<c:otherwise>
								<option value="author">作者</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='abstract'}">
								<option value="abstract" selected="selected">摘要</option>
							</c:when>
							<c:otherwise>
								<option value="abstract">摘要</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='keyword'}">
								<option value="keyword" selected="selected">关键词</option>
							</c:when>
							<c:otherwise>
								<option value="keyword">关键词</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='company'}">
								<option value="company" selected="selected">作者单位</option>
							</c:when>
							<c:otherwise>
								<option value="company">作者单位</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='time'}">
								<option value="time" selected="selected">发布日期</option>
							</c:when>
							<c:otherwise>
								<option value="time">发布日期</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='bm'}">
								<option value="bm" selected="selected">发布部门</option>
							</c:when>
							<c:otherwise>
								<option value="bm">发布部门</option>
							</c:otherwise>
						</c:choose>
						<c:choose>
							<c:when test="${category=='wh'}">
								<option value="wh" selected="selected">文号</option>
							</c:when>
							<c:otherwise>
								<option value="wh">文号</option>
							</c:otherwise>
						</c:choose>
					</select>
				</div>

				<div class="col-md-6">
					<div class="input-group">
						<input type="text" class="form-control" value="${content}" id="search_content" placeholder="请输入要搜索的内容" autocomplete="on"> <span class="input-group-btn">
							<button class=" btn btn-warning" type="button" id="search_button">
								<span class="myfont" class="">检索</span>
							</button>
						</span>
					</div>
				</div>
				<div class="col-md-3">
					<div class="input-group" style="margin-top: 10px">
						<a href="../information/infoadsearch.jsp"><span style="font-size: 28;" class="text-primary">高级检索</span></a>
					</div>
					<input type="text" value="${reczsk_id}" hidden="true" id="reczsk_id"> 
					<input type="text" hidden="true" id="tag_name"> 
					<input type="text" hidden="true" id="time">
				</div>
			</div>
		</div>
		<div class="row clearfix">
			<div class="col-md-3 column">
				<h4 class="heading">类别</h4>
				<div class="myline"></div>
				<div class="panel panel-default" style="height: 780px">
					<ul id="treeDemo" class="ztree" style="background-color: #FFFFFF; border: 0px; overflow-y: auto; overflow-x: auto;"></ul>
				</div>
			</div>
			<div class="col-md-9 column">
				<ul id="myTab" class="nav nav-tabs">

				</ul>
				<div class="panel panel-default">
					<div id="myTabContent" class="tab-content"></div>
					<div class="myline" style="margin-top: 20px"></div>
				</div>
				<div id="table_content" style="margin-top: 0px;">
					<table id="tb_departments"></table>
				</div>
			</div>
		</div>
		<div class="row clearfix" style="margin-top:0px">
			<div class="col-md-12 column">
				<%@include file="../common/bottom.jsp"%>
			</div>
		</div>
	</div>
	
	
	
	<div class="modal fade" id="sendEmail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">请输入您要发送的邮箱</h4>
				</div>
				<div class="modal-body">
					<input id="toemail" name="toemail" type="text" class="form-control"> 
					<input id="name" name="name" type="text" hidden="true"> 
					<input id="url" name="url" type="text" hidden="true">
					<input id="currentTab" name="currentTab" type="text" hidden="true">
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" onclick="send()">发送</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
	
	
	
</body>
<script type="text/javascript">
	var taglist;
	var role='<%=rolename%>';
	var userid='<%=userid%>';
	var  searchcontent;//控制更多展开还是收缩

	//zTree树的参数

	var setting = {
		data : {
			simpleData : {
				enable : true
			}
		},
		view : {
			showLine : false,
			showIcon : false,
			checkable : true
		},
		check : {
			enable : true
		}
	};

	//BootStrap初始化

	$(function() {
		$("#role").val(role);
		$("#userid").val(userid);

		searchcontent='${content}';
		
		treeinit();
		//1.初始化Table

		var oTable = new TableInit();
		oTable.Init();

		//2.初始化Button的点击事件

		var oButtonInit = new ButtonInit();
		oButtonInit.Init();
		//标签初始化

 		var reczsk_id = getReczskIDS();
		changeTag(reczsk_id);
		decorate();
	});

	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table

		oTableInit.Init = function() {
			$('#tb_departments')
					.bootstrapTable(
							{
								url : '../information/getSearchInformation', //请求后台的URL（*）

								method : 'get', //请求方式（*）

								toolbar : '#toolbar', //工具按钮用哪个容器

								striped : true, //是否显示行间隔色

								cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）

								pagination : true, //是否显示分页（*）

								sortable : true, //是否启用排序

								sortOrder : "asc", //排序方式

								queryParams : oTableInit.queryParams,//传递参数（*）

								sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）

								pageNumber : 1, //初始化加载第一页，默认第一页

								pageSize : 15, //每页的记录行数（*）

								pageList : [10, 25, 50, 100], //可供选择的每页的行数（*）

								search : false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大

								strictSearch : true,
								showColumns : false, //是否显示所有的列

								showRefresh : false, //是否显示刷新按钮

								minimumCountColumns : 2, //最少允许的列数

								clickToSelect : true, //是否启用点击选中行

								height : 700, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度

								uniqueId : "info_id", //每一行的唯一标识，一般为主键列

								showToggle : false, //是否显示详细视图和列表视图的切换按钮

								cardView : false, //是否显示详细视图

								detailView : false, //是否显示父子表

								columns : [
										{
											field : 'info_name',
											title : '题名',
											width : '33%',
											formatter : function(value,row,index) {
												var element = "<a onclick='check(\""+row.info_id+"\",\""+row.info_keyword+"\")' data-id='"+ row.info_id+ "'><span class='text-primary'>"+ row.info_name+ "</span></a>&nbsp;&nbsp";
												return element;
											}
										}, 
										{
											field : 'info_author',
											title : '作者',
											width : '13%'
										},
										{
											field : 'info_bm',
											title : '发布部门',
											width : '12%'
										},
										{
											field : 'info_time',
											title : '发布时间',
											width : '12%'
										},
										{
											field : 'library',
											title : '库',
											width : '10%'
										},
										{
											field : 'info_download',
											title : '下载',
											width : '5%',
										},
										{
											field : 'info_browser',
											title : '浏览',
											width : '5%',
										},
										{
											field : 'operate',
											title : '操作',
											width : '10%',
											formatter : function(value, row,
													index) {
												var element;
												
												element = '<img id="collectimage" class="img-thumbnail" onclick="down(\''+row.info_url+'\',\''+row.info_id+'\',\''+row.info_status+'\',\''+row.info_level+'\')" data-toggle="popover" data-trigger="hover" title="下载" style="height: 25px; width: 25px; border: none;margin-left:5px" src="../../image/icon/download.png">'
/*  															+'<img id="emailimage"  onclick="moopen(\''+ row.info_url+ '\',\''+row.info_name+'\',\''+row.info_level+'\')"  class="img-thumbnail" data-toggle="popover" data-trigger="hover" title="发送到邮箱" style="height: 25px; width: 25px; border: none; float: left" src="../../image/icon/mail.png">'
 */ 															return element;
											}
										}]
							});
		};
		//得到查询的参数

		oTableInit.queryParams = function(params) {
			var reczsk_id = getReczskIDS();
			var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的

				limit : params.limit, //页面大小

				offset : params.offset, //页码初始开始值

				category : $("#category").val(),
				content :searchcontent,
				reczsk_id : reczsk_id,
				tag_name : $("#tag_name").val(),
				time : $("#time").val()
			};
			return temp;
		};
		return oTableInit;
	};

	var ButtonInit = function() {
		var oInit = new Object();
		oInit.Init = function() {
			//初始化页面上面的按钮事件

			$('#search_button').bind('click', function() {
				searchcontent = $("#search_content").val();
				$("#tag_name").val("");
				$("#time").val("");
				$('#tb_departments').bootstrapTable('refreshOptions',{pageNumber:1});
				var reczsk_id = getReczskIDS();
				changeTag(reczsk_id);
				decorate();
			});
		};
		return oInit;
	};
	//zTree树的初始化

	function treeinit(){
		
		//zTree树的初始化

		var treeNode;
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			url : "../configration/getReczsk",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				treeNode = data;
			}
		});
		var tree=$.fn.zTree.init($("#treeDemo"), setting, treeNode);
		

		//根据传过来的reczsk_id选择zTree节点并展开

		var reczsk_id = $("#reczsk_id").val();
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		if (reczsk_id != '') {
			var node = zTree.getNodeByParam("id", reczsk_id);
			var funode = zTree.getNodeByParam("id", reczsk_id.substring(0, 3));
			zTree.checkNode(node, true, true);
			zTree.expandNode(funode);
		}
		/* else{

			zTree.checkAllNodes(true);

		} */
		tree.expandAll(true);

		
	}
	
	//根据库ID获取相应库的标签内容
	function changeTag(reczsk_id) {
		$.ajax({
			async : false,
			cache : false,
			type : 'POST',
			dataType : "json",
			data : {
				category : $("#category").val(),
				content : $("#search_content").val(),
				reczsk_id : reczsk_id,
				tag_name : $("#tag_name").val(),
				time : $("#time").val(),
			},
			url : "../information/updateforSearchTag",
			error : function() {
				alert('请求失败');
			},
			success : function(data) {
				taglist = data;
				initTab(taglist);
			}
		});//AJAX结束

	}
	
	function moopen(url,name){
		var userid = '<%=userid%>';
		
		if(userid==""){
			window.location.href="../common/login.jsp";
		}
		else{
			var modal = $("#sendEmail");
			modal.modal("show");
			modal.find('#name').val(name);
			modal.find('#url').val(url);
		}
		
	}
</script>
</html>